<template>
  <div id="pie" :style="{width: '100%', height: '400px'}"></div>
</template>

<script>
export default {
  props: {
    legendData: {
      type: Array,
      default: []
    },
    seriesData: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      polar: {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        grid: {
          left: 'center'
        },
        legend: {
          bottom: '10px',
          left: 'left',
          data: this.legendData
        },
        series: [
          {
            name: '数据',
            type: 'pie',
            radius: '45%',
            center: ['50%', '50%'],
            data: this.seriesData,
            label: {
              show: false
            },
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
    }
  },
  created() {
    this.$nextTick(() => {
      var dom = document.getElementById('pie')
      console.log('dom', dom)

      var myChart = this.echarts.init(dom, 'light')
      this.polar.legend.data = this.legendData
      this.polar.series[0].data = this.seriesData
      console.log('legendData', this.legendData, this.seriesData, this.polar)

      myChart.setOption(this.polar)
    })
  }
}
</script>